((expr,par)=>{
    let util={};
    par.forEach((info)=>{
        util[info.name]=info.value;
        if(info.type==="string"){
            String.prototype[info.name]=info.value;
        }else if(info.type==="object"){
           Object.prototype[info.name]=info.value;
        }
    });
    expr.util=util;
})(window,[{
    name:"RmSpace",
    type:"string",
    value:function(str=this){
        if(!str){
            return str;
        }
        str=this.toString();
        return str.trim().replace(/\s/,"");
    }
},{
    name:"GetFnVal",
    type:"string",
    value:function(){
        let str=this;
        if(!str){
            return str;
        }
        str=this.toString();
        try {
            return eval("(function(a){return a;})("+str+")");
        }catch (e) {
            return str;
        }
    }
},{
    name:"GetCenterVal",
    type:"string",
    value:function(before,after){
        let str=this;
        if(!str){
            return str;
        }
        str=this.toString();
        let p="([.\\s\\S]*?)";
        if(before){
            p="(?<="+before+")"+p;
        }
        if(after){
            p=p+"(?="+after+")";
        }

        try {
            return str.match(new RegExp(p,"g"))[0];
        }catch (e) {
            return null;
        }
    }
},{
    name:"UnJson",
    type:"string",
    value:function(){
        let str=this;
        if(!str){
            return str;
        }
        str=this.toString();
        try {
            return eval("("+str+")");
        }catch (e) {
            return null;
        }
    }
}]);


function init(){
    var sList=[],list=$("div.item");
    list.each((i,t)=>{
        let d=$(t);
        let info={};
        //取信息
        info.title=d.find(".title").text().RmSpace();
        info.commodity=d.find(".title a").attr("href").RmSpace();
        info.id=d.find(".title a").attr("data-nid").RmSpace();
        info.money=d.find(".title a").attr("trace-price").RmSpace();
        info.address=d.find(".location").text().RmSpace();
        info.shop={
            name:d.find(".J_ShopInfo").text().RmSpace(),
            id:d.find(".J_ShopInfo").attr("data-userid").RmSpace(),
            url:d.find(".J_ShopInfo").attr("href").RmSpace(),
            ww:(d.find(".ww-small").attr("data-nick")||"").RmSpace(),
            wwUrl:(d.find(".ww-small a").attr("href")||"").RmSpace()
        };
        //ajax
        get_text_data("https://item.taobao.com/item.htm?id="+info.id,(obj)=>{
            let json=obj.data.GetCenterVal("TShop.Setup\\(","\\);");
            if(json){
                //天猫
                //console.log(json.UnJson());
            }else{
                //淘宝店
                json=obj.data.GetCenterVal("g_config =",";");
                if(json){
                    console.log(json.UnJson())
                }
            }
        });
        sList.push(info);
    });
    console.log(sList);
    
}
console.log("init");
let time=setInterval(()=>{
    if($("div.item").length>0){
        clearInterval(time);
        init();
    }
},200);